library(xlsx)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(stringr)
library(dplyr)
library(tibble)
library(ggplot2)
library(org.Hs.eg.db)
## Loading required package: AnnotationDbi
## Loading required package: stats4
## Loading required package: BiocGenerics
## 
## Attaching package: 'BiocGenerics'
## 
## The following objects are masked from 'package:lubridate':
## 
##     intersect, setdiff, union
## 
## The following objects are masked from 'package:dplyr':
## 
##     combine, intersect, setdiff, union
## 
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## 
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, append, as.data.frame, basename, cbind, colnames,
##     dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
##     grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
##     order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
##     rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
##     union, unique, unsplit, which.max, which.min
## 
## Loading required package: Biobase
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## 
## Loading required package: IRanges
## Loading required package: S4Vectors
## 
## Attaching package: 'S4Vectors'
## 
## The following objects are masked from 'package:lubridate':
## 
##     second, second<-
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, rename
## 
## The following object is masked from 'package:tidyr':
## 
##     expand
## 
## The following objects are masked from 'package:base':
## 
##     expand.grid, I, unname
## 
## 
## Attaching package: 'IRanges'
## 
## The following object is masked from 'package:lubridate':
## 
##     %within%
## 
## The following objects are masked from 'package:dplyr':
## 
##     collapse, desc, slice
## 
## The following object is masked from 'package:purrr':
## 
##     reduce
## 
## 
## Attaching package: 'AnnotationDbi'
## 
## The following object is masked from 'package:dplyr':
## 
##     select
library(clusterProfiler)
## 
## Registered S3 method overwritten by 'ggtree':
##   method      from 
##   identify.gg ggfun
## clusterProfiler v4.2.2  For help: https://yulab-smu.top/biomedical-knowledge-mining-book/
## 
## If you use clusterProfiler in published research, please cite:
## T Wu, E Hu, S Xu, M Chen, P Guo, Z Dai, T Feng, L Zhou, W Tang, L Zhan, X Fu, S Liu, X Bo, and G Yu. clusterProfiler 4.0: A universal enrichment tool for interpreting omics data. The Innovation. 2021, 2(3):100141
## 
## Attaching package: 'clusterProfiler'
## 
## The following object is masked from 'package:AnnotationDbi':
## 
##     select
## 
## The following object is masked from 'package:IRanges':
## 
##     slice
## 
## The following object is masked from 'package:S4Vectors':
## 
##     rename
## 
## The following object is masked from 'package:purrr':
## 
##     simplify
## 
## The following object is masked from 'package:stats':
## 
##     filter
library(DOSE)
## DOSE v3.20.1  For help: https://yulab-smu.top/biomedical-knowledge-mining-book/
## 
## If you use DOSE in published research, please cite:
## Guangchuang Yu, Li-Gen Wang, Guang-Rong Yan, Qing-Yu He. DOSE: an R/Bioconductor package for Disease Ontology Semantic and Enrichment analysis. Bioinformatics 2015, 31(4):608-609
library(msigdbr)
library(enrichplot)
library(ggrepel)
library(ggpubr)
## 
## Attaching package: 'ggpubr'
## 
## The following object is masked from 'package:enrichplot':
## 
##     color_palette
library(ComplexHeatmap)
## Loading required package: grid
## ========================================
## ComplexHeatmap version 2.10.0
## Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
## Github page: https://github.com/jokergoo/ComplexHeatmap
## Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
## 
## If you use it in published research, please cite:
## Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
##   genomic data. Bioinformatics 2016.
## 
## The new InteractiveComplexHeatmap package can directly export static 
## complex heatmaps into an interactive Shiny app with zero effort. Have a try!
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(ComplexHeatmap))
## ========================================
library(circlize)
## ========================================
## circlize version 0.4.15
## CRAN page: https://cran.r-project.org/package=circlize
## Github page: https://github.com/jokergoo/circlize
## Documentation: https://jokergoo.github.io/circlize_book/book/
## 
## If you use it in published research, please cite:
## Gu, Z. circlize implements and enhances circular visualization
##   in R. Bioinformatics 2014.
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(circlize))
## ========================================

1 KHOS Xgraft

PATH = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/xgrafts/out/01_raptor_exprtools/KHOS/"
PATH_GSEA_ORA = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/xgrafts/out/02_GSEA_ORA/KHOS/"
COMP = "WTvsEZHIP"
CELL = 'KHOS'
deg.khos = read.csv(paste(PATH, "diff/hg19.Ensembl.ensGene.exon/", COMP, '.tsv', sep=""), sep="\t")
counts.khos = read.csv(paste(PATH, "counts/hg19.Ensembl.ensGene.exon.norm.tsv.gz", sep=""), sep="\t")
load(paste0(PATH_GSEA_ORA, CELL, '_', COMP, '.Rda'))
write.xlsx(GOBP %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, "KHOS_xgraft_GSEA.xlsx"), sheetName="GOBP", row.names=FALSE)
write.xlsx(Hall %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, "KHOS_xgraft_GSEA.xlsx"), sheetName="HALLMARK", append=TRUE, row.names=FALSE)
Hall %>% as.data.frame()
p = (Hall_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `across("ID", str_replace_all, "_", " ")`.
## Caused by warning:
## ! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
## Supply arguments directly to `.fns` through an anonymous function instead.
## 
##   # Previously
##   across(a:b, mean, na.rm = TRUE)
## 
##   # Now
##   across(a:b, \(x) mean(x, na.rm = TRUE))
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (Hall %>% as.data.frame())[1:20,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p2 = gseaplot2(Hall,
          geneSetID = c('KRAS_SIGNALING_UP', 'MYOGENESIS', 'EPITHELIAL_MESENCHYMAL_TRANSITION'), 
          color = c('#337357', '#CD5334', '#FFB41F')) 
p2

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_HALLMARK_GSEA_plot.pdf"), width = 7, height = 5)
p2
dev.off()
## png 
##   2
p = (GOBP_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.01, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - GOBP')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_GOBP_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (dolgalev_atlas %>% as.data.frame())[1:14,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' Xeno - Dolgalev')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Dolgalev_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baryawno_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' Xeno - Baryawno')) +
  coord_flip() +
  scale_y_continuous(expand = c(0,0)) 
  

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baryawno_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baccin_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' Xeno - Baccin')) +
  coord_flip() +
  scale_y_continuous(expand = c(0,0)) 
  

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baccin_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (zhang_atlas %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' Xeno - Zhang')) +
  coord_flip() +
  scale_y_continuous(expand = c(0,0)) 
  

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Zhang_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2

2 MG63 Xgraft

PATH = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/xgrafts/out/01_raptor_exprtools/MG63/"
PATH_GSEA_ORA = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/xgrafts/out/02_GSEA_ORA/MG63/"
COMP = "WTvsEZHIP"
CELL = 'MG63'
deg.mg63 = read.csv(paste(PATH, "diff/hg19.Ensembl.ensGene.exon/", COMP, '.tsv', sep=""), sep="\t")
counts.mg63 = read.csv(paste(PATH, "counts/hg19.Ensembl.ensGene.exon.norm.tsv.gz", sep=""), sep="\t")
load(paste0(PATH_GSEA_ORA, CELL, '_', COMP, '.Rda'))
p = (dolgalev_atlas %>% as.data.frame())[1:14,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' Xeno - Dolgalev')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Dolgalev_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baryawno_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' Xeno - Baryawno')) +
  coord_flip() 

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baryawno_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baccin_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' Xeno - Baccin')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baccin_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (zhang_atlas %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' Xeno - Zhang')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Zhang_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
write.xlsx(GOBP %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, "MG63_xgraft_GSEA.xlsx"), sheetName="GOBP", row.names=FALSE)
write.xlsx(Hall %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, "MG63_xgraft_GSEA.xlsx"), sheetName="HALLMARK", append=TRUE, row.names=FALSE)
Hall_ora_up %>% as.data.frame()

CA2/PRRX1/SATB1/PTGS2/CPE/EPB41L3/GPRC5B/SERPINA3/MMP9/BMP2/RGS16/RELN/NAP1L2/ID2/SPP1/CCND2/MMP11/ACE/IL1B/TNFRSF1B

p = (Hall_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.1, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('#E26565'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.1', '>0.1')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (Hall %>% as.data.frame())[1:20,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
genes = str_split((Hall_ora_up %>% as.data.frame() %>% filter(ID == "HALLMARK_EPITHELIAL_MESENCHYMAL_TRANSITION"))$geneID, pattern = '/')

h = counts.mg63 %>% 
  rownames_to_column('ID') %>%
  separate(ID, into =  c('ENS', 'SYM'), sep = ":") %>%
  filter(SYM %in% genes[[1]]) %>%
  select(-ENS) %>%
  column_to_rownames('SYM') 

h = scale(t(h)) %>%
    t()

col_fun = colorRamp2(c(-2, 0, 2), c("steelblue", "beige", "firebrick"))

h1 = Heatmap(h, 
         col = col_fun,
        name = 'z-score', 
        width = ncol(h)*unit(5, "mm"), 
        height = nrow(h)*unit(4, "mm"), 
        show_column_names = F, 
        show_row_dend = F, 
        column_title = 'EMT',
        bottom_annotation = HeatmapAnnotation(Cond = c(rep('EZHIP', 3), rep('WT', 2)), 
                                               col = list(Cond = c('EZHIP' = "red", 'WT' = "blue"))))

draw(h1)

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_HALLMARK_EPITHELIAL_MESENCHYMAL_TRANSITION.pdf"), width = 10, height = 10)
draw(h1)
dev.off()
## png 
##   2
Hall %>% as.data.frame()
p2 = gseaplot2(Hall,
          geneSetID = c('KRAS_SIGNALING_UP', 'MYOGENESIS', 'EPITHELIAL_MESENCHYMAL_TRANSITION'), 
          color = c('#337357', '#CD5334', '#FFB41F')) 
p2

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_HALLMARK_GSEA_plot.pdf"), width = 7, height = 5)
p2
dev.off()
## png 
##   2
p = (GOBP_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.005, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_GOBP_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2

3 U2OS Cell Line

PATH = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/U2OS/out/01_raptor_exprtools/EZHIP_minus_C77_C2/"
PATH_GSEA_ORA = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/U2OS/out/02_GSEA_ORA_minus_C77_C2//"
COMP = "EZHIP_KOvsEZHIP"
CELL = 'U2OS'
deg.u2os = read.csv(paste(PATH, "diff/Ensembl.ensGene.exon/", COMP, '.tsv', sep=""), sep="\t")
counts.u2os= read.csv(paste(PATH, "counts/Ensembl.ensGene.exon.raw.tsv.gz", sep=""), sep="\t")
load(paste0(PATH_GSEA_ORA, CELL, '_', COMP, '.Rda'))
p = (dolgalev_atlas %>% as.data.frame())[1:14,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Dolgalev')) +
  coord_flip() +
  scale_y_continuous(expand = c(0, 0))
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Dolgalev_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baryawno_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Baryawno')) +
  coord_flip() +
  scale_y_continuous(expand = c(0, 0))

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baryawno_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baccin_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Baccin')) +
  coord_flip() +
  scale_y_continuous(expand = c(0,  0))
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baccin_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (zhang_atlas %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Zhang')) +
  coord_flip() +
  scale_y_continuous(expand = c(0,  0))
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Zhang_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
write.xlsx(GOBP %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, "U2OS_cell_line_GSEA.xlsx"), sheetName="GOBP", row.names=FALSE)
write.xlsx(Hall %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, "U2OS_cell_line_GSEA.xlsx"), sheetName="HALLMARK", append=TRUE, row.names=FALSE)
Hall %>% as.data.frame()
p = (Hall_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (Hall %>% as.data.frame())[1:20,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip() +
  scale_y_continuous(expand = c(0,0))

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
genes = str_split((Hall_ora_up %>% as.data.frame() %>% filter(ID == "HALLMARK_EPITHELIAL_MESENCHYMAL_TRANSITION"))$geneID, pattern = '/')

h = cbind(counts.khos, counts.mg63) %>% 
  rownames_to_column('ID') %>%
  separate(ID, into =  c('ENS', 'SYM'), sep = ":") %>%
  filter(SYM %in% genes[[1]]) %>%
  select(-ENS) %>%
  column_to_rownames('SYM') 

h = scale(t(h)) %>%
    t()

col_fun = colorRamp2(c(-2, 0, 2), c("steelblue", "beige", "firebrick"))

h1 = Heatmap(h, 
         col = col_fun,
        name = 'z-score', 
        width = ncol(h)*unit(5, "mm"), 
        height = nrow(h)*unit(4, "mm"), 
        show_column_names = F, 
        show_row_dend = F, 
        column_title = 'EMT',
        bottom_annotation = HeatmapAnnotation(Cond = c(rep('EZHIP', 3), rep('WT', 3), rep('EZHIP', 3), rep('WT', 2)), 
                                              `Cell line` = c(rep('KHOS', 6), rep('MG63', 5)),
                                               col = list(Cond = c('EZHIP' = "red", 'WT' = "blue"))))

draw(h1)

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_HALLMARK_EPITHELIAL_MESENCHYMAL_TRANSITION.pdf"), width = 10, height = 10)
draw(h1)
dev.off()
## png 
##   2
p2 = gseaplot2(Hall,
          geneSetID = c('KRAS_SIGNALING_UP', 'MYOGENESIS', 'EPITHELIAL_MESENCHYMAL_TRANSITION'), 
          color = c('#337357', '#CD5334', '#FFB41F')) 
p2

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_HALLMARK_GSEA_plot.pdf"), width = 7, height = 5)
p2
dev.off()
## png 
##   2
p = (GOBP_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.005, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - GOBP')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_GOBP_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2

4 hMSC Cell Line

PATH = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/hMSC/out/01_raptor_exprtools/EZHIP/"
PATH_GSEA_ORA = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/hMSC/out/02_GSEA_ORA/"
COMP = "WTvsEZHIP"
CELL = 'hMSC'
deg.hMSC.cell = read.csv(paste(PATH, "diff/Ensembl.ensGene.exon/", COMP, '.tsv', sep=""), sep="\t")
counts.hMSC.cell = read.csv(paste(PATH, "counts/Ensembl.ensGene.exon.raw.tsv.gz", sep=""), sep="\t")
load(paste0(PATH_GSEA_ORA, CELL, '_', COMP, '.Rda'))
p = (dolgalev_atlas %>% as.data.frame())[1:14,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Dolgalev')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Dolgalev_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baryawno_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Baryawno')) +
  coord_flip() +
  scale_y_continuous(expand = c(0, 0))

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baryawno_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baccin_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Baccin')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baccin_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (zhang_atlas %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Zhang')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Zhang_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
write.xlsx(GOBP %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, CELL, "_xgraft_GSEA.xlsx"), sheetName="GOBP", row.names=FALSE)
write.xlsx(Hall %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, CELL, "_xgraft_GSEA.xlsx"), sheetName="HALLMARK", append=TRUE, row.names=FALSE)
Hall %>% as.data.frame()
p = (Hall_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (Hall %>% as.data.frame())[1:20,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip() 

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
GOBP %>% as.data.frame()
p = (GOBP_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (GOBP %>% as.data.frame())[1:20,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip() 

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_GOBP_barplot.pdf"), width = 10, height = 5)
p
dev.off()
## png 
##   2

5 MG63 Cell Line

PATH = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/MG63/out/01_raptor_exprtools/EZHIP/"
PATH_GSEA_ORA = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/MG63/out/02_GSEA_ORA/"
COMP = "WTvsEZHIP"
CELL = 'MG63'
deg.mg63.cell = read.csv(paste(PATH, "diff/Ensembl.ensGene.exon/", COMP, '.tsv', sep=""), sep="\t")
counts.mg63.cell = read.csv(paste(PATH, "counts/Ensembl.ensGene.exon.raw.tsv.gz", sep=""), sep="\t")
load(paste0(PATH_GSEA_ORA, CELL, '_', COMP, '.Rda'))
p = (dolgalev_atlas %>% as.data.frame())[1:14,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Dolgalev')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Dolgalev_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baryawno_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Baryawno')) +
  coord_flip() +
  scale_y_continuous(expand = c(0, 0))

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baryawno_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baccin_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Baccin')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baccin_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (zhang_atlas %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Zhang')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Zhang_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
write.xlsx(GOBP %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, CELL, "_xgraft_GSEA.xlsx"), sheetName="GOBP", row.names=FALSE)
write.xlsx(Hall %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, CELL, "_xgraft_GSEA.xlsx"), sheetName="HALLMARK", append=TRUE, row.names=FALSE)
write.xlsx(GOBP %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, CELL, "_xgraft_GSEA.xlsx"), sheetName="GOBP", row.names=FALSE)
write.xlsx(Hall %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, CELL, "_xgraft_GSEA.xlsx"), sheetName="HALLMARK", append=TRUE, row.names=FALSE)
Hall %>% as.data.frame()
p = (Hall_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (Hall %>% as.data.frame())[1:20,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip() 

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2

6 KHOS Cell Line

PATH = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/KHOS/out/01_raptor_exprtools/EZHIP/"
PATH_GSEA_ORA = "/lustre06/project/6004736/alvann/from_narval/220318_EZHIP/RNA/KHOS/out/02_GSEA_ORA/"
COMP = "WTvsEZHIP"
CELL = 'KHOS'
deg.khos.cell = read.csv(paste(PATH, "diff/Ensembl.ensGene.exon/", COMP, '.tsv', sep=""), sep="\t")
counts.khos.cell = read.csv(paste(PATH, "counts/Ensembl.ensGene.exon.raw.tsv.gz", sep=""), sep="\t")
load(paste0(PATH_GSEA_ORA, CELL, '_', COMP, '.Rda'))
p = (dolgalev_atlas %>% as.data.frame())[1:14,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Dolgalev')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Dolgalev_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baryawno_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Baryawno')) +
  coord_flip() 

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baryawno_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (baccin_atlas %>% as.data.frame())[1:15,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Baccin')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Baccin_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (zhang_atlas %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Zhang')) +
  coord_flip() 
  
p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Zhang_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
write.xlsx(GOBP %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, CELL, "_xgraft_GSEA.xlsx"), sheetName="GOBP", row.names=FALSE)
write.xlsx(Hall %>% as.data.frame(), file=paste0(PATH_GSEA_ORA, CELL, "_xgraft_GSEA.xlsx"), sheetName="HALLMARK", append=TRUE, row.names=FALSE)
Hall %>% as.data.frame()
p = (Hall_ora_up %>% as.data.frame())[1:10,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +Count), y = Count, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  scale_y_continuous(expand = c(0,0)) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip()

p

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_ORA_UP_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2
p = (Hall %>% as.data.frame())[1:20,] %>% 
  mutate(sign = ifelse(p.adjust < 0.05, 'p.adjust < 0.05', NA)) %>%
  mutate(across('ID', str_replace_all, '_', ' '), 
         across('ID', str_replace_all, 'HALLMARK', ' ')) %>%
  ggplot(aes(x =  reorder(ID, +NES), y = NES, fill = sign)) +
  geom_bar(stat = 'identity') +
  scale_fill_manual(values = c('firebrick'), na.value = 'lightgrey', name = 'p-val', labels = c('<0.05', '>0.05')) +
  theme_bw() +
  theme(text = element_text(size = 15), 
        axis.title.y = element_blank(),
        axis.line = element_line(size = 0.5), 
        panel.border = element_blank(), 
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank()) +
  ggtitle(paste0(CELL, ' - Hallmark')) +
  coord_flip() 

pdf(paste0(PATH_GSEA_ORA, CELL, '_', COMP, "_GSEA_Hallmark_barplot.pdf"), width = 7, height = 5)
p
dev.off()
## png 
##   2